package com.whfc.iot.mach.codec;

import com.whfc.iot.mach.entity.MachMsg;
import com.whfc.iot.mach.util.MachMsgUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 冷藏车硬件消息-编码器
 */
public class MachMsgDecoder extends MessageToMessageDecoder<ByteBuf> {

    private Logger logger = LoggerFactory.getLogger(MachMsgDecoder.class);

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        //状态检查
        if (!in.isReadable()) {
            return;
        }

        MachMsg msg = MachMsgUtil.decode(in);

        out.add(msg);
    }

}
